---
title: Go Scripting
sidebar_position: 90
---

# Scripting ORAS in Go

It is possible to use the ORAS CLI in Go scripts.
When you are scripting ORAS in Go, the parameters should be specified just like they are on the command line.
This feature is experimental and may be subject to breaking changes in the future.

For example:

```go
package main
import (
	"fmt"
	"os"
	"strings"
	"oras.land/oras/cmd/oras/root"
)
func main() {
	// change below array to play with your own cmd args:
	args := []string{"repo", "ls", "mcr.microsoft.com"}
	cmd := root.New()
	cmd.SetArgs(args)
	builder := &strings.Builder{}
	cmd.SetOut(builder)
	fmt.Printf("Executing 'oras %s':", strings.Join(args, " "))
	err := cmd.Execute()
	fmt.Println(builder.String())
	if err != nil {
		fmt.Errorf("Failed to execute : %w", err)
		os.Exit(-1)
	}
	os.Exit(0)
}
```

To run this example:
```
mkdir example
cd example
go mod init example
go mod edit --require oras.land/oras@v1.2.0
# copy the example code into the directory...
cat >main.go
go mod tidy
go run main.go
```
